export default function initTouch(props,setupCtx,common){
	// let rootdom = {top:0,left:0}
	// let dm = document.querySelectorAll('uni-main')[0]
	// if(dm === undefined){
	//   dm = document.querySelectorAll('uni-page-wrapper')[0]
	// }
	// rootdom = {top:dm.offsetTop,left:dm.offsetLeft}
	function tap(e) {
		if(!common.uChartsInstance || !props.ontap) return;
	  let rchartdom = document.getElementById(common.containerId).getBoundingClientRect();
	  let tmpe = {};
		// console.log(e.detail.x,e.detail.y,rchartdom);
	  if(e.detail.x){//tap或者click的事件
	    tmpe = { x: e.detail.x - rchartdom.left, y:e.detail.y - rchartdom.top};
	  }else{//mouse的事件
	    tmpe = { x: e.clientX - rchartdom.left, y:e.clientY - rchartdom.top};
	  }
	  e.changedTouches.unshift(tmpe)
	  let currentIndex = common.uChartsInstance.getCurrentDataIndex(e);
	  let legendIndex = common.uChartsInstance.getLegendDataIndex(e);
	  if(props.tapLegend){
	    common.uChartsInstance.touchLegend(e);
	  }
	  if(props.tooltipShow){
	    common.showTooltip(e);
	  }
	  // that[cid].callMethod('emitMsg',{name:"getIndex",params:{type:"getIndex",event:tmpe,currentIndex:currentIndex,legendIndex:legendIndex,id:cid, opts: cfu.instance[cid].opts}})
	}
	function touchstart(e) {
		if(!common.uChartsInstance) return;
	  // let cid = this.rid
	  // let ontouch = cfu.option[cid].ontouch
	  // if(ontouch == false) return;
	  common.uChartsInstance.scrollStart(e);
	  // that[cid].callMethod('emitMsg',{name:"getTouchStart",params:{type:"touchStart",event:e.changedTouches[0],id:cid}})
	}
	function touchmove(e) {
		if(!common.uChartsInstance) return;
	  // let cid = this.rid
	  // let ontouch = cfu.option[cid].ontouch
	  // if(ontouch == false) return;
	  common.uChartsInstance.scroll(e);
	  // that[cid].callMethod('emitMsg',{name:"getTouchMove",params:{type:"touchMove",event:e.changedTouches[0],id:cid}})
	  // if(cfu.option[cid].ontap === true && cfu.option[cid].enableScroll === false && cfu.option[cid].onmovetip === true){
	  //   let rchartdom = document.getElementById('UC'+cid).getBoundingClientRect()
	  //   let tmpe = { x: e.changedTouches[0].clientX - rchartdom.left, y:e.changedTouches[0].clientY - rchartdom.top + rootdom.top}
	  //   e.changedTouches.unshift(tmpe)
	  //   if(cfu.option[cid].tooltipShow === true){
	  //     this.showTooltip(e,cid)
	  //   }
	  // }
	}
	function touchend(e) {
		if(!common.uChartsInstance) return;
	  // let cid = this.rid
	  // let ontouch = cfu.option[cid].ontouch
	  // if(ontouch == false) return;
	  common.uChartsInstance.scrollEnd(e);
	  // that[cid].callMethod('emitMsg',{name:"getTouchEnd",params:{type:"touchEnd",event:e.changedTouches[0],id:cid}})
	}
	return {
		tap,
		touchstart,
		touchmove,
		touchend
	}
}